#include<bits/stdc++.h>
using namespace std;
char _be;
typedef struct{
	int mx,add_mx,add_cnt,add_ans;
}OP;
OP f[30000011];
void Merge(OP& A,OP B)
{
	A.mx = max(A.mx + B.add_mx,B.mx),A.add_mx += B.add_mx,A.add_cnt += B.add_cnt,A.add_ans += B.add_ans;
}
int idx;
int bgn[4000011];
int n,q;
int a[1000011];
void Build(int p,int l,int r)
{
	if(l == r)
	{
		bgn[p] = ++idx;
		idx++;
		if(a[l])
			f[bgn[p]] = {0,-1,1,0},f[bgn[p] + 1] = {0,-1,1,0};
		else
			f[bgn[p]] = {1,0,0,1},f[bgn[p] + 1] = {1,1,-1,0};
		return;
	}
	int mid = l + r >> 1;
	Build(p << 1,l,mid),Build(p << 1 | 1,mid + 1,r);
	int len = r - l + 1,llen = mid - l + 1,rlen = r - mid;
	bgn[p] = ++idx;
	idx += len;
	for(int i = 0;i <= len;i++)
	{
		OP& Nw = f[bgn[p] + i];
		Nw = f[bgn[p << 1] + min(llen,i)];
		OP R = f[bgn[p << 1 | 1] + min(rlen,i + Nw.add_cnt)];
		Merge(Nw,R);
	}
}
OP res;
void ask(int p,int l,int r,int ll,int rr)
{
	if(l <= ll && rr <= r)
		return Merge(res,f[bgn[p] + min(rr - ll + 1,res.add_cnt)]);
	int mid = ll + rr >> 1;
	if(l <= mid)
		ask(p << 1,l,r,ll,mid);
	if(mid < r)
		ask(p << 1 | 1,l,r,mid + 1,rr);
}
char _ed;
int main()
{
	double be = clock();
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("good.in","r",stdin);
	freopen("good.out","w",stdout);
	cin >> n >> q;
	for(int i = 1;i <= n;i++)
		cin >> _ed,a[i] = (_ed - '0');
	Build(1,1,n);
	int ans = 0;
	while(q--)
	{
		int l,r;
		cin >> l >> r;
		res = {0,0,0,0};
		ask(1,l,r,1,n);
		ans ^= res.mx + res.add_ans;
	}
	cout << ans;
	cerr << idx << "\n";
	cerr << "Time: " << (clock() - be) / CLOCKS_PER_SEC << "sec Memory: " << ((&_be) - (&_ed)) / 1024.0 / 1024.0 << "MB" << endl;
	return 0;
}